from machine import Pin
from machine import FPIOA
import time

fpioa = FPIOA()

#fpioa.set_function(62, FPIOA.GPIO62)
#fpioa.set_function(20, FPIOA.GPIO20)
#fpioa.set_function(63, FPIOA.GPIO63)

fpioa.set_function(62, FPIOA.GPIO62, ie = 0, oe = 1, pu = 0, pd = 0, st = -1, sl = -1, ds = 7)
fpioa.set_function(20, FPIOA.GPIO20, ie = 0, oe = 1, pu = 0, pd = 0, st = -1, sl = -1, ds = 7)
fpioa.set_function(63, FPIOA.GPIO63, ie = 0, oe = 1, pu = 0, pd = 0, st = -1, sl = -1, ds = 7)

LED_R = Pin(62, Pin.OUT, pull=Pin.PULL_NONE, drive = 7)
LED_G = Pin(20, Pin.OUT, pull=Pin.PULL_NONE, drive = 7)
LED_B = Pin(63, Pin.OUT, pull=Pin.PULL_NONE, drive = 7)


#LED_R.value(1) #等价于 LED_R.high() == LED_R.on()
#LED_G.value(1)
#LED_B.value(0)

LED_R.off()
LED_G.off()
LED_B.off()

def led_blink(r, g, b, delay):
    set_color(r, g, b)
    time.sleep(delay)
    set_color(0, 0, 0)
    time.sleep(delay)

def set_color(r, g, b):
    if r == 0:
        LED_R.high()
    elif r == 1:
        LED_R.low()

    if g == 0:
        LED_G.high()
    elif g == 1:
        LED_G.low()

    if b == 0:
        LED_B.high()
    elif b == 1:
        LED_B.low()



while True:
    led_blink(1, 1, 1, 0.5)

    led_blink(1, 1, 0, 0.5)

    led_blink(1, 0, 1, 0.5)

    led_blink(1, 0, 0, 0.5)

    led_blink(0, 1, 1, 0.5)

    led_blink(0, 1, 0, 0.5)

    led_blink(0, 0, 1, 0.5)


    '''
    LED_B.high()
    LED_R.low()
    time.sleep(0.5)
    LED_R.high()
    LED_G.low()
    time.sleep(0.5)
    LED_G.high()
    LED_B.low()
    time.sleep(0.5)
    '''
